%From: Wing Cheong Lau %Subject: LSH matlab tuning example x = 0:0.01:1 ; r1 = 5 ; b1 = 10 ; r2 = 5 ; b2 = 10 ; %x = sim(A,B) = Prob. [minhash(A) = minhash(B)] %Example for AND-OR: i.e. y = Prob [ Among b1 bands, there is at least one that contains exact match in all r1 rows within that band ] y = 1 - ( 1 - x.^r1 ).^b1 ; plot(x,y) ; hold on ; %Example for OR-AND: y1 = Prob [ For all b1 bands, there is at least one row out of the r1 rows in each band that is a match ] y1 = ( 1 - (1 - x).^r1 ).^b1 ; plot(x,y1) ; %Example (AND-OR) followed by OR-AND: %(AND-OR) (i.e. perform r1*b1 tests form one Preliminary (AND-OR) test of "similar-enough", %repeat such preliminary test r2*b2 times and a pair is declared to pass the final similarity test, %if it can pass at least one preliminary test in every band of the b2 bands of Phase2 tests: % the probability of passing the final test as a function of sim(A,B) is given by z: z = ( 1 - (1 - y).^r2 ).^b2 ; plot(x,z) %Example (OR-AND) followed by AND-OR: %(OR-AND) (i.e. perform r1*b1 tests form one Preliminary (OR-AND) test of "similar-enough", %repeat such preliminary test r2*b2 times and a pair is declared to pass the final similarity test %if among all of the b2 band of Phase 2 tests, there is at least one band which passes all of the r2 preliminary tests: % the probability of passing the final test as a function of sim(A,B) is given by z2: z2 = ( 1 - (1 - y1).^r2 ).^b2 ; plot(x,z2) %---------- % Example of AND-OR followed by AND-OR, again, again, and again make the jump across the same threshold sharper and sharper !! z1 = 1 - ( 1 - y.^r1 ).^b1 ; plot(x,z1) ; z3 = 1 - ( 1 - z1.^r1 ).^b1 ; plot(x,z3) ; z4 = 1 - ( 1 - z3.^r1 ).^b1 ; plot(x,z4) ; %---------- %Example of OR-AND followed by OR-AND, and then OR-AND again, and again,... z5 = ( 1 - (1 - y1).^r1 ).^b1 ; plot(x,z5) ; z6 = ( 1 - (1 - z5).^r1 ).^b1 ; plot(x,z6) ; z7 = ( 1 - (1 - z6).^r1 ).^b1 ; plot(x,z7) ; plot(x,x) ; hold ;